// pages/projectRecord/projectRecord.js
const db = wx.cloud.database();
const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    activeKey: "one",
    haveData1: false,
    haveData2: false,
    haveData3: false,
    haveData4: false,
    // myDeliveryRecord: [],
    firstTagData: [],
    secondTagData: [],
    thirdTagData: [],
    fourthTagData: []
  },

  navToJobDetail(e) {
    wx.showLoading({
      title: '请求中',
      mask: true
    })
    console.log(e);
    db.collection('job').doc(e.currentTarget.dataset.job_id).get({
      success: res => {
        console.log(res.data);
        app.navTmpInfo = res.data;
        wx.navigateTo({
          url: '/pages/job_detail/job_detail',
        })
      },
      fail: res => {
        console.log(res);
      },
      complete: function () {
        wx.hideLoading();
      }
    })

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    let that = this;
    db.collection('resume').where({
      _openid: app.personInfo._openid
    }).get({
      success: res => {
        if (res.data.length != 0) {
          let firstTagData = [];
          let secondTagData = [];
          let thirdTagData = [];
          let fourthTagData = [];
          for (let i = 0; i < res.data.length; i++) {
            if (res.data[i].status == "待查看") {
              firstTagData.push(res.data[i]);
            } else if (res.data[i].status == "已邀面") {
              secondTagData.push(res.data[i]);
            } else if (res.data[i].status == "已拒绝") {
              thirdTagData.push(res.data[i]);
            } else if (res.data[i].status == "已录用") {
              fourthTagData.push(res.data[i]);
            }
          }
          that.setData({
            firstTagData,
            secondTagData,
            thirdTagData,
            fourthTagData,
          });


          if (firstTagData.length != 0) {
            that.setData({
              haveData1: true
            })
          }
          if (secondTagData.length != 0) {
            that.setData({
              haveData2: true
            })
          }
          if (thirdTagData.length != 0) {
            that.setData({
              haveData3: true
            })
          }
          if (fourthTagData.length != 0) {
            that.setData({
              haveData4: true
            })
          }
        }
      },
      fail: res => {

      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})